

<div class="layui-form" lay-filter="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <input type="text" lay-verify="required" name="group_name" value="{{ d.params.group_name || '' }}" lay-verify="required" placeholder="角色名称" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">权限范围</label>
    <div class="layui-input-block" id="perms">

    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="hidden" name="opt" value="add">
      <input type="button" lay-submit lay-filter="LAY-user-role-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form'], function(){
  var $ = layui.$
      , admin = layui.admin
      ,form = layui.form;
    admin.req({
        url: layui.setter.api + 'admins/perms'
        , method: 'get'
        , success: function (data) {
            if (data.code == 0) {
                var info = data.data;
                var html = '';
                for (var key in info) {
                    html += '<div style="color:#FF5722;position:relative;font-size: 12px;top: 5px;">'+info[key]['title']+'</div>';
                    for(var k in info[key]['list']){
                      html += '<input type="checkbox" name="group_perm[]" value="'+info[key]['list'][k]['name']+'" lay-skin="primary" title="'+info[key]['list'][k]['title']+'">'
                    }

                }
                $("#perms").html(html);
                form.render();
            }
        }
    });
});
</script>
